WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
eigen_assert.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
21#include <Eigen/Dense>
22
23namespace Eigen
24{
26/* Check Eigen Matrix sizes, both statically and dynamically
27 *
28 * Help:
29 *
30 * The WOLF project implements many template functions using Eigen Matrix and Quaterniond, in different versions
31 * (Static size, Dynamic size, Map, Matrix expression).
32 *
33 * Eigen provides some macros for STATIC assert of matrix sizes, the most common of them are (see Eigen's
34 * StaticAssert.h):
35 *
36 * EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE
37 * EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE
38 * EIGEN_STATIC_ASSERT_VECTOR_ONLY
39 *
40 * but they do not work if the evaluated types are of dynamic size.
41 *
42 * In order to achieve full templatization over both dynamic and static sizes, we use extensively a prototype of this
43 * kind:
44 *
45 * template<typename Derived>
46 * inline Eigen::Matrix<typename Derived::Scalar, 3, 3> function(const Eigen::MatrixBase<Derived>& _v){
47 *
48 * MatrixSizeCheck<3,1>::check(_v); /// We check here the size of the input parameter
49 *
50 * typedef typename Derived::Scalar T;
51 *
52 * ... code ...
53 *
54 * return M;
55 * }
56 *
57 * The function : MatrixSizeCheck <Rows, Cols>::check(M) checks that the Matrix M is of size ( Rows x Cols ).
58 * This check is performed statically or dynamically, depending on the type of argument provided.
59 */
62template <int Size, int DesiredSize>
64{
67 template <typename T>
69 {
70 static_assert(Size == DesiredSize, "Size of static Vector or Matrix does not match");
71 }
72};
73
76template <int DesiredSize>
77struct StaticDimCheck<Eigen::Dynamic, DesiredSize>
78{
81 template <typename T>
82 StaticDimCheck(const T& t)
83 {
84 if (t != DesiredSize) std::cerr << "t : " << t << " != DesiredSize : " << DesiredSize << std::endl;
85 assert(t == DesiredSize && "Size of dynamic Vector or Matrix does not match");
86 }
87};
88
91template <int DesiredR, int DesiredC>
93{
102 template <typename T>
103 static void check(const Eigen::MatrixBase<T>& t)
104 {
107 }
108};
109
111template <int Dim>
113
115template <int Dim>
117
118} /* namespace Eigen */
Namespace extending Eigen definitions.
Definition: wolf.h:91
Size check of an Eigen matrix: static for fixed sizes, at run time for dynamic sizes.
Definition: eigen_assert.h:93
static void check(const Eigen::MatrixBase< T > &t)
Asserts the matrix size dynamically or statically.
Definition: eigen_assert.h:103
StaticDimCheck(const T &t)
Asserts at run time that the size matches.
Definition: eigen_assert.h:82
Static assertion of the size of a fixed-size Eigen matrix (see MatrixSizeCheck)
Definition: eigen_assert.h:64
StaticDimCheck(const T &)
Asserts statically that the size matches.
Definition: eigen_assert.h:68